﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ZK.MyControl
{
    public class ActionListBox:ListBox
    {
        delegate void Delegate_Fuc();
        delegate void Delegate_FucStr(object obj);

        /// <summary>
        /// ListBox 委托
        /// </summary>
        public void Add( object obj)
        {

            if (this.InvokeRequired)
            {
                Delegate_FucStr delegate_Fuc = new Delegate_FucStr(Add);

                this.Invoke(delegate_Fuc, new object[] { obj });
            }
            else
            {
                this.Items.Add(obj);
            }
        }

        /// <summary>
        /// ListBox 委托
        /// </summary>
        public void Remove( object obj)
        {

            if (this.InvokeRequired)
            {

                Delegate_FucStr delegate_Fuc = new Delegate_FucStr(Remove);

                this.Invoke(delegate_Fuc, new object[] { obj });

            }
            else
            {
                this.Items.Remove(obj);

            }
        }

        /// <summary>
        /// ListBox 委托
        /// </summary>
        public void RemoveFirst()
        {

            if (this.InvokeRequired)
            {
                Delegate_Fuc delegate_Fuc = new Delegate_Fuc(RemoveFirst);

                this.Invoke(delegate_Fuc);
            }
            else
            {
                this.Items.RemoveAt(0);

            }
        }


        /// <summary>
        /// ListBox 委托
        /// </summary>
        public void DelegateClear()
        {

            if (this.InvokeRequired)
            {
                Delegate_Fuc delegate_Fuc = new Delegate_Fuc(DelegateClear);

                this.Invoke(delegate_Fuc);
            }
            else
            {
                this.Items.Clear();

            }
        }
    }
}
